org.mentalsmash.asksusanna.gui.Debugger = function(phrase,conf) {
	
	var subphrases = phrase.getSubphrases();
	var words = phrase.getWords();
	
	var buildWordBox = function(word) {
		var wordDebug = $('<div></div>');
		wordDebug.addClass('debug');

		var roundScore = Math.round(word.normalizedScore() * Math.pow(10,2)) / Math.pow(10,2);
		
		
		var totalHits = 0;
		
		var subphrasesBox = $('<div class="subphrases"></div>');
		
		$(word.getPhrases()).each(function(i,sph){
			var hits = phrase.getSubphraseHits(sph);
			var score = phrase.getSubphraseScore(sph);
			totalHits += hits;
			var box = $('<p>'+'<span class="label">'+sph+'</span>' + '<span class="value">' + '[ hits: '+hits+', score: '+score+' ]'+ '</span>'+'</p>');
			subphrasesBox.append(box);
		});

		wordDebug.html(
						'<p>'+
							'<span class="label">'+'Word : ' + '</span>' + '<span class="value">' + word.getWord() + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Score : ' + '</span>' + '<span class="value">' + word.getScore() + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'MaxScore : ' + '</span>' + '<span class="value">' + word.getMaxScore() + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'MinScore : ' + '</span>' + '<span class="value">' + word.getMinScore() + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Normalized Score : ' + '</span>' + '<span class="value">' + word.normalizedScore() + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Rounded : ' + '</span>' + '<span class="value">' + roundScore + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Total Hits : ' + '</span>' + '<span class="value">' + totalHits + '</span>'+
						'</p>'
		);
		
		wordDebug.append(subphrasesBox);

		return wordDebug;
	}
	
	var buildPhraseBox = function(subph, hits, score, parameters) {
		var subphDebug = $('<div></div>');
		subphDebug.addClass('debug');

		subphDebug.html(
						'<p>'+
							'<span class="label">'+'Phrase : ' +'</span>' + '<span class="value">' +  subph + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Hits : ' +'</span>' + '<span class="value">' +  hits + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Score : ' +'</span>' + '<span class="value">' +  score + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Length : ' +'</span>' + '<span class="value">' +  subph.words().length + '</span>'+
						'</p>'+
						'<p>'+
							'<span class="label">'+'Scoring Parameters : ' +'</span>' +
							'<span class="value">hits = [' +  parameters.hits.min + ',' + parameters.hits.score0 + ',' + parameters.hits.max + '], scores = ['+parameters.scores.min +',' + parameters.scores.max + ']</span>'+
						'</p>'
		);
		
		return subphDebug;
	}
	
	return {
		'getDebugBox' : function() {
			var container = $('<div id="debugger"></div>');

			var wboxes = [];

			$(words).each(function(i,word){
				var wbox = buildWordBox(word);
				wboxes.push(wbox);
			});

			var subphboxes = [];

			$(subphrases).each(function(i,subph){
				var hits = phrase.getSubphraseHits(subph);
				var score = phrase.getSubphraseScore(subph);
				var phbox = buildPhraseBox(subph,hits,score,conf.getPhraseParameters(subph));
				subphboxes.push(phbox);
			});

			var phraseDiv = $('<div class="phrase"></div>');
			phraseDiv.append($('<p>'+phrase.getPhrase()+'</p>'))

			container.append(phraseDiv);
			
			var wordsDiv = $('<div class="words"></div>');
			$(wboxes).each(function(i,wbox){
				wordsDiv.append(wbox);
			});
			
			container.append(wordsDiv);
			
			var subphrasesDiv = $('<div class="subphrases"></div>');
			$(subphboxes).each(function(i,subphbox){
				subphrasesDiv.append(subphbox);
			});
			
			container.append(subphrasesDiv);
			
			return container;
		}
	};
	
}